import {
  Controller,
  Delete,
  forwardRef,
  Get,
  Inject,
  Query,
} from '@nestjs/common'
import { ApiOperation, ApiTags } from '@nestjs/swagger'

import { IdParam } from '~/common/decorators/id-param.decorator'
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator'
import { definePermission, Perm } from '~/modules/auth/decorators/permission.decorator'

import { UserAlarmService } from '~/modules/health/user/userAlarm.service'
import { SseService } from '~/modules/sse/sse.service'
import { UserAlarmQueryDto } from './userAlarm.dto'

export const permissions = definePermission('health:userAlarm', {
  LIST: 'list',
  CREATE: 'create',
  READ: 'read',
  UPDATE: 'update',
  DELETE: 'delete',
} as const)

@ApiTags('Health - 告警信息模块')
@ApiSecurityAuth()
@Controller('users/alarm')
export class UserAlarmController {
  constructor(
    private userAlarmService: UserAlarmService,
    @Inject(forwardRef(() => SseService))
    private sseService: SseService,
  ) {}

  @Get('')
  @ApiOperation({ summary: '告警数据查询' })
  @Perm(permissions.LIST)
  async listAlarm(@Query() dto: UserAlarmQueryDto): Promise<any> {
    return this.userAlarmService.listAlarm(dto)
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除告警数据' })
  @Perm(permissions.DELETE)
  async deleteAlarm(@IdParam() id: number): Promise<void> {
    await this.userAlarmService.deleteAlarm(id)
  }
}
